#!/usr/bin/python
from struct import pack
from struct import unpack
from struct import calcsize
import FileStruct
"""Functions to test FileStruct class."""

def test_store(location = "/home/user/test1.tmp", destination = "/home/other/test2.tmp", is_dir = 0, host_id = -1, state_id = 0, size = 1234567890, comp_str = '\xd2\x02\x96I\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00\x14\x00\x00\x00\x15\x00\x00\x00/home/user/test1.tmp/home/other/test2.tmp'):
	"""Test store function for correct bitstring ouput."""
	obj = FileStruct.FileStruct(location, is_dir, host_id, size)
	obj.set_destination(destination)
	obj.set_state_id(state_id)
	test_str = FileStruct.store(obj)
	if not comp_str == test_str:
		print "FileStruct Error: strings do not match, generated string: `", test_str,"'"

def test_create(location = "/home/user/test1.tmp", destination = "/home/other/test2.tmp", is_dir = 0, host_id = -1, state_id = 0, size = 1234567890, comp_str = '\xd2\x02\x96I\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00\x14\x00\x00\x00\x15\x00\x00\x00/home/user/test1.tmp/home/other/test2.tmp'):
	"""Test create function for corect nitstring parsing."""
	obj=FileStruct.create(comp_str)
	if not obj.get_size()==size:
		print "FileStruct Error: Size does not match, generated:", obj.get_size(), " original:", size
	if not obj.get_state_id() == state_id:
		print "FileStruct Error: State_id does not match, generated:", obj.get_state_id, " original:", state_id
	if not obj.get_host_id() == host_id:
		print "FileStruct Error: Host_id does not match, generated:", obj.get_host_id(), " orirginal:", host_id
	if not obj.is_dir() == is_dir:
		print "FileStruct Error: Is_dir does not match, generated:", obj.is_dir(), "original:", is_dir
	if not obj.get_location() == location:
		print "FileStruct Error: Location does not match, generated:", obj.get_location(), "original:", location
	if not obj.get_destination() == destination:
		print "FileStruct Error: Destination does not match, generated:", obj.get_destination(), "original:", destination

if __name__=='__main__':
	print "FileStruct: Testing store function."
	test_store()
	test_store(destination="",comp_str='\xd2\x02\x96I\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00/home/user/test1.tmp')
	print "FileStruct: Testing create function."
	test_create()
	test_create(destination="",comp_str = '\xd2\x02\x96I\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00/home/user/test1.tmp')
